<#assign contextPath=springMacroRequestContext.getContextPath()/>
<#import "/public/frame/main.html" as frame/>
<@frame.head "南航明珠商城-畅销商品管理"></@frame.head>
<link rel="stylesheet" type="text/css" href="${contextPath}/resources/css/search_table.css"/>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i>后台管理中心 <span class="c-gray en">&gt;</span>促销管理 <span class="c-gray en">&gt;</span>畅销商品管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">
		<form action="${contextPath}/sell_well_product/query_list" method="post" name="search_form" id="search_form">
			<input type="hidden" name="page" value="${pagination.pageNo}"  id="page"/>  
			<table class="table search_table">
				<tr>
					<td colspan="8" style="text-align: left;vertical-align:middle;">
						<div id="mySwitch" class="switch size-S" style="float: left;" data-animated="false" data-on-label="开" data-off-label="关">
							<#if showFlag == "1">
					    	<input type="checkbox" checked="checked"/>
					    	<#else>
					    	<input type="checkbox"/>
					    	</#if>
					    </div>
						<div style="display: inline-block; float: left; margin-top: 3px; margin-left: 10px; color: red;font-size: small;font-weight: bold;">根据商品所属供应商展示</div>
					</td>
				</tr>
				<tr>  
           			<td>商品编号：</td>
           			<td>
           				<input class="input-text radius" placeholder="请输入商品编号" name="prodNo" value="${sellWellProductQo.prodNo}" onkeyup='this.value=this.value.replace(/\D/g,"")'/>
           			</td>
           			<td>商品名称：</td>
           			<td>
           				<input class="input-text radius"  placeholder="请输入商品名称" name="name" value="${sellWellProductQo.name}"/>
          			</td>  
           			<td>发布时间：</td>
           			<td>
	           			<input onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'endDate\')}',readOnly: true })" id="startDate" style="width: 45%;"
	               		value='${(sellWellProductQo.startPubDate?string("yyyy-MM-dd"))!}' name="startPubDate" class="input-text Wdate">
	               		至
	               		<input onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'startDate\')}',readOnly: true })" id="endDate" style="width: 45%;"
	               		value='${(sellWellProductQo.endPubDate?string("yyyy-MM-dd"))!}' name="endPubDate" class="input-text Wdate">
           			</td> 
           			<td>
              			<input class="btn btn-success radius" type="button" onclick="search();" value="搜索" />
           			</td>
					<td>
						<input class="btn btn-success radius" type="button" onclick="toIsEmpty();" value="重置" />
					</td>
         		</tr>
			</table>
		</form>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
	    <span class="l">
	    	<a href="javascript:;" onclick="addProduct('发布畅销商品');" class="btn btn-primary radius">发布畅销商品</a> 
	    	<a href="javascript:;" onclick="delProduct();" class="btn btn-warning radius">批量删除</a> 
	    </span>
    	<span class="r">共有数据：<strong>${pagination.totalCount}</strong> 条</span>
    </div>
    <table class="table table-border table-bordered table-bg">
        <thead>
	        <tr class="text-c">
				<th><input  type="checkbox" id="selectAll"/></th>
	            <th>商品编号</th>
	            <th>商品名称</th>
	            <th>发布时间</th>
	            <th>开始时间</th>
	            <th>结束时间</th>
	            <th>显示位置</th>
	            <th>状态</th>
	            <th>操作</th>
			</tr>
		</thead>
		<tbody>
	         <#list pagination.list as list> 
		         <tr class="text-c">
					<td><input type="checkbox" name="chk" value="${list.id?c}" /></td>
		            <td>${list.product.id}</td>
		            <td>${list.product.baseInfo.name}</td>
		            <td>${(list.pubDate?string("yyyy-MM-dd HH:mm:ss"))!}</td>
		            <td>${(list.startDate?string("yyyy-MM-dd"))!}</td>
		            <td>${(list.endDate?string("yyyy-MM-dd"))!}</td>
		            <td>${list.position}</td>
		            <td>
			            <#if list.status==2>畅销
			            <#else>不畅销
			            </#if>
		            </td>
		            <td>
			            <#if list.status==2>
			            <a href="javascript:;"  onclick="cancleSellWell('${list.id?c}');">取消畅销</a>
			            <#else>
			            <a href="javascript:;"  onclick="setSellWell('${list.id?c}','${list.position}');">畅销</a>
			            </#if>
						<a href="javascript:;"  onclick="deleteProduct('${list.id?c}');">删除</a>
		     		</td>
	         	</tr>
	         </#list>
        </tbody>
    </table>
    <div id="div_page" style="padding-top: 10px;float: right"></div>
</div>
<@frame.end "default"></@frame.end>
<script type="text/javascript" src="${contextPath}/resources/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="${contextPath}/resources/js/laypage/laypage.js"></script>
<script type="text/javascript" src="${contextPath}/resources/js/sell_well_product/query_list.js"></script>
<script type="text/javascript">
var path = "${contextPath}";
laypage({
    cont: "div_page",//容器。值支持id名、原生dom对象，jquery对象。
    pages: ${pagination.totalPage},//通过后台拿到的总页数
    curr:  ${pagination.pageNo} || 1, //当前页
	skip: true, //是否开启跳页
	first: 1, //将首页显示为数字1,。若不显示，设置false即可
	last: ${pagination.totalPage}, //将尾页显示为总页数。若不显示，设置false即可
    jump: function(obj , first){//触发分页后的回调
        if(!first){ //点击跳页触发函数;当前页为obj.curr
            $("#page").val(obj.curr);
            $("#search_form").submit();
        }
    }
});

var switchEven = function (e, data) {
	layer.load(2); // 遮罩层
	var value = data.value;
    $.ajax({
    	type: "post",
    	url: path + "/sell_well_product/updateProductShowFlag",
    	data: {
    		showFlag: value ? "1" : "0"
    	},
    	dataType: "text",
    	success: function(data) {
    		layer.closeAll("loading");
    		if(data == "success") {
    			
    		} else {
    			layer.alert(data, function (index) {
        			$("#mySwitch").off("switch-change"); // 解绑switch事件
            		$("#mySwitch").bootstrapSwitch("setState", !value); // 还原switch值
            		$("#mySwitch").on("switch-change", switchEven); // 绑定switch事件
            		layer.closeAll("loading"); // 关闭遮罩层
            		layer.close(index); // 关闭本提示框
        		});
    		}
    	},
    	error: function(e) {
    		layer.alert("切换失败！", function (index) {
    			$("#mySwitch").off("switch-change"); // 解绑switch事件
        		$("#mySwitch").bootstrapSwitch("setState", !value); // 还原switch值
        		$("#mySwitch").on("switch-change", switchEven); // 绑定switch事件
        		layer.closeAll("loading"); // 关闭遮罩层
        		layer.close(index); // 关闭本提示框
    		});
    	}
    });
};
$("#mySwitch").on("switch-change", switchEven);

</script>